package second.codeTop.package1;

/**
 * @ClassName LC121
 * @description:
 * @author: 荣燊
 * @create: 2022-04-02 13:54
 **/
public class LC121 {
    public static void main(String[] args) {
        int[] a = {7,1,5,3,6,4};
        System.out.println(maxProfit(a));
    }

    // dp[i] = prices[i] - min{prices[0~i-1]}
    public static int maxProfit(int[] prices) {
        int res = 0;
        int min = prices[0];
        for (int i=1; i<prices.length; i++) {
            if (prices[i] > min) {
                res = Math.max(res, prices[i]-min);
            } else {
                min = prices[i];
            }
        }
        return res;
    }
}
